#ifndef _CLOCK_H
#define _CLOCK_H

#include <hal/rtc.h>
#include <compiler.h>

static inline time_t rtc_to_unix(rtc_time_t* t) {
    return (t->year - 1970) * 31556926U
        + (t->month - 1) * 2629743U
        + (t->day - 1) * 86400U
        + (t->hour - 1) * 3600U
        + (t->minute - 1) * 60U
        + t->second;
}

static inline time_t time_to_unix(u32 yyyy, u32 mm, u32 dd, u32 hh, u32 MM, u32 ss) {
    return (yyyy - 1970) * 31556926U
        + (mm - 1) * 2629743U
        + (dd - 1) * 86400U
        + (hh - 1) * 3600U + (MM - 1) * 60U + ss;
}

#endif /* _CLOCK_H */